#!/bin/ksh

LOGIN=$1
SH_DIR=$2
UP_DIR=$3
UP_FILE=$4

sqlplus -s $LOGIN<<!
DELETE FROM scj.scj_tmp_upload_sales;
COMMIT;
!

cat > $UP_DIR/ctl/Upload_SCJ_Sales.ctl<<!
LOAD DATA
INFILE '$UP_DIR/$UP_FILE'
APPEND INTO TABLE scj.scj_tmp_upload_sales
FIELDS TERMINATED BY ';'
TRAILING NULLCOLS
(
network,
hw_code,
total_qty,
total_amt,
x_co_qty,
x_co_amt,
x_rs_qty,
x_rs_amt,
x_cs_qty,
x_cs_amt,
x_re_qty,
x_re_amt,
x_ts_qty,
x_ts_amt,
x_ad_qty,
x_ad_amt,
x_ec_qty,
x_ec_amt,
x_ed_qty,
x_ed_amt,
x_ot_qty,
x_ot_amt,
n_co_qty,
n_co_amt,
n_rs_qty,
n_rs_amt,
n_cs_qty,
n_cs_amt,
n_re_qty,
n_re_amt,
n_ts_qty,
n_ts_amt,
n_ad_qty,
n_ad_amt,
n_ec_qty,
n_ec_amt,
n_ed_qty,
n_ed_amt,
n_ot_qty,
n_ot_amt,
r_co_qty,
r_co_amt,
r_rs_qty,
r_rs_amt,
r_cs_qty,
r_cs_amt,
r_re_qty,
r_re_amt,
r_ts_qty,
r_ts_amt,
r_ad_qty,
r_ad_amt,
r_ec_qty,
r_ec_amt,
r_ed_qty,
r_ed_amt,
r_ot_qty,
r_ot_amt,
s_co_qty,
s_co_amt,
s_rs_qty,
s_rs_amt,
s_cs_qty,
s_cs_amt,
s_re_qty,
s_re_amt,
s_ts_qty,
s_ts_amt,
s_ad_qty,
s_ad_amt,
s_ec_qty,
s_ec_amt,
s_ed_qty,
s_ed_amt,
s_ot_qty,
s_ot_amt,
o_co_qty,
o_co_amt,
o_rs_qty,
o_rs_amt,
o_cs_qty,
o_cs_amt,
o_re_qty,
o_re_amt,
o_ts_qty,
o_ts_amt,
o_ad_qty,
o_ad_amt,
o_ec_qty,
o_ec_amt,
o_ed_qty,
o_ed_amt,
o_ot_qty,
o_ot_amt
)
!

/usr/local/bin/dos2unix $UP_DIR/$UP_FILE
sqlldr $LOGIN \
control=$UP_DIR/ctl/Upload_SCJ_Sales.ctl bad=$UP_DIR/bad/Upload_SCJ_Sales.bad \
log=$UP_DIR/log/Upload_SCJ_Sales.log >> $UP_DIR/log/Upload_SCJ_Sales.log

